﻿/*   
    Copyright (C) 2009 Galaktika Corporation ZAO

    This file is a part of Galaktika.BusinessMonitor
 
    Galaktika.BusinessMonitor is a free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
      
    You should have received a copy of the GNU General Public License
    along with Galaktika.BusinessMonitor.  If not, see <http://www.gnu.org/licenses/>.
  
    If GPL v.3 is not suitable for your products or company,
    Galaktika Corp provides Galaktika.BusinessMonitor under a flexible commercial license
    designed to meet your specific usage and distribution requirements.
    If you have already obtained a commercial license from Galaktika Corp,
    you can use this file under those license terms.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

namespace Galaktika.BI.Silverlight.ClientApp.Web.DAL
{
    using Galaktika.BI.Extensibility.Dom;

    [System.Runtime.Serialization.DataContractAttribute(Name = "DalVariable", Namespace = Common.Namespace)]
    [XmlRoot("DalVariable", Namespace = Common.Namespace)]
    public class DalVariable : DalObject
    {
        public DalVariable()
        {
        }

        public DalVariable(string name)
            : base(name, name)
        {
        }

        public DalVariable(string name, string title)
            : base(name, title)
        {
        }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 2)]
        public string Connection { get; set; }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 3)]
        public string CubeName { get; set; }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 4)]
        public string Value { get; set; }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 5)]
        public string DefaultValue { get; set; }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 6)]
        public string CurrentValue { get; set; }

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 7)]
        public string TypeCode { get; set; }

        private List<DalPrincipalValue> m_PrincipalValues;
        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 8)]
        [XmlArray]
        [XmlArrayItem(typeof(DalPrincipalValue))]
        public List<DalPrincipalValue> PrincipalValues
        {
            get
            {
                if (m_PrincipalValues == null)
                {
                    m_PrincipalValues = new List<DalPrincipalValue>();
                }

                return m_PrincipalValues;
            }
        }

        [XmlElement]
        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 9)]
        public string Description { get; set; }

        [XmlElement]
        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 10)]
        public VariableChangedAction ChangeAction { get; set; }

        //public BrickVariable ToBrick()
        //{
        //    return new BrickVariable(this.Title, this.Name, this.Value, this.CurrentValue, this.TypeCode);
        //}

        public DalVariable Clone()
        {
            DalVariable var = new DalVariable(this.Name, this.Title);
            var.CurrentValue = this.CurrentValue;
            var.Value = this.Value;
            var.TypeCode = this.TypeCode;
            var.ChangeAction = this.ChangeAction;

            return var;
        }
    }
}
